package com.backend.demo.util;

public class ObjectUtil {

	/**
	 * 判断两个对象是否不相等
	 * 
	 * @param o1
	 * @param o2
	 * @return
	 */
	public static boolean notEquals(Object o1, Object o2) {
		if (o1 == null)
			return o2 != null;
		return !o1.equals(o2);
	}

	/**
	 * 判断两个对象是否相等,两个都为null时,对象相等
	 * 
	 * @param o1
	 * @param o2
	 * @return
	 */
	public static boolean equals(Object o1, Object o2) {
		if (o1 == null)
			return o2 == null;
		return o1.equals(o2);
	}

	public static String toString(Object obj) {
		if (obj == null)
			return null;
		return obj.toString();
	}

	/**
	 * 得到一个或多个对象的hashCode
	 * 
	 * @param fields
	 * @return
	 */
	public static int hashCode(Object... fields) {

		int result = 0;
		if (fields != null) {
			for (Object f : fields) {
				result = 29 * result + (f == null ? 0 : f.hashCode());
			}
		}

		return result;
	}

	public static void notifyWakeup(Object obj) {
		if (obj == null)
			return;
		synchronized (obj) {
			obj.notifyAll();
		}
	}

	/**
	 * 转换long数组
	 */
	public Long[] switchLong(long[] ads) {
		Long[] temp = new Long[ads.length];
		for (int i = 0; i < ads.length; i++) {
			temp[i] = ads[i];
		}
		return temp;
	}
}
